<template>
  <div id="appSettingTopSearch">
    <div class="search-box">
      <el-form
        ref="searchForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        @submit.native.prevent
      >
        <el-form-item label="活动名称" prop="activityName">
          <el-select v-model="formInline.activityId" filterable placeholder="请输入活动名称">
            <el-option
              v-for="item in activityList"
              :key="item.activityId"
              :label="item.activityName"
              :value="item.activityId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间：">
          <el-date-picker
            style="width:400px"
            v-model="formInline.time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            搜索
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
          <el-button type="warning" icon="el-icon-plus" @click="addGift">
            新增
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>

export default {
  watch: {
    'formInline.time': {
      immediate: true,
      handler(newV, oldV) {
        if (newV == null) {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        } else {
          this.formInline.startTime = newV[0]
          this.formInline.endTime = newV[1]
        }
      },
      deep: true
    }
  },
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          activityName: '', // 参数名称
          endTime: '', // 结束时间
          status: '', // 状态
          time: []
        }
      }
    },
    activityList: {
      type: Array,
      default:()=>[]
    }
  },
  data() {
    return {
      time: []
    }
  },
  methods: {
    // 搜索
    toSearch() {
      this.$emit('toSearch')
    },
    // 重置
    reset() {
      this.$refs.searchForm.resetFields()
      this.setDefaultValue()
    },
    addGift() {
      this.$emit('addGift')
    },
    setDefaultValue() {
      this.formInline.activityId = ''
      this.formInline.time = ''
      this.formInline.startTime = ''
      this.formInline.endTime = ''
    }
  }
}
</script>
<style lang="less"></style>
